<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./react/react.development.js"></script>
    <script src="./react/react-dom.development.js"></script>
    <script src="./react/babel.min.js"></script>
    <script src="./react/prop-types.js"></script>
    <script src="./react/lodash.min.js"></script>
    <script src="./react/immutable.min.js"></script>

</head>
<body>
<div id="app"></div>
<script type="text/babel">

    let app = document.querySelector('#app');

    let root = ReactDOM.createRoot(app);

    class Head extends React.PureComponent {
        render(){
            console.log('render');
            return (
                <div>head component, {this.props.item.get('text')} </div>
            );
        }
    }

    class Welcome extends React.PureComponent {
        state = {
            msg: 'hello',
            count: 0,
            //性能更好
            list: Immutable.fromJS([
                {id:1,text:'aaa'}
            ])
        }
        handleClick = () => {
            //let list = [...this.state.list];
            //let list = _.cloneDeep(this.state.list);
            let list = this.state.list.setIn([0,'text'],'bbb')
            list[0].text = 'bbb';
            this.setState({
                list
            });
        }
        render(){
            return (
                <div>
                    <button onClick={this.handleClick}>点击</button>
                    <Head item={this.state.list.get(0) } />
                </div>
            );
        }
    }
    let element = (
        <Welcome />
    );


    root.render(element);



</script>
</body>
</html>